import pagination from '@/views/pagination'  //分页组件
import agentHttp from '@/utils/agentHttp'    //请求方法
import router from '@/router'
import dialogForm from './edit'
import {debounce} from '@/utils/index.js'
export default {
  name: 'carorderList',
  components:{dialogForm,pagination},
  created(){
    this.seachData(this.searchForm);
    this.getStatusMap();
  },
  data() {
  	return {
      //搜索字段
  		searchForm:{
  			dealerName:"",
  			carBrandNameAndCarName:"",
  			status:"",
  			orderNumber:"",
        startDate:"",
        endDate:"",
        logisticsInfoStatus:"",
        type:"",
        carInspectionInfoStatus:"",
        depositInfoStatus:"",
        logisticsFollowStatus:"",
        vin:"",

  		},
       //表格字段
      tableData: [],
      formLabelWidth:'120px',
      statusMap:'',
      orderTypeMap:'',
      logisticsStatusMap:'',
      cashDepositStatusMap:'',
      carInspectionStatusMap:'',
      logisticsFollowStatusMap:'',
      //发送给弹窗的数据
      dialogSendData:{
        isAdd:true,                //是否为编辑或者新增  true是   false否
        dialogFormVisible:false,   //弹窗是否显示        true是   false否
        id:"",          //请求参数            自定义 例如index或者id
        isBack:true
      },
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now() 
        }
      },
      endDateOpt:{
          disabledDate:(time)=>{
            return  time.getTime()< new Date(this.searchForm.startDate).getTime();
          }
      },
      resetFormStatus:false  
        
  	}
  },

  methods: {
     seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.postJson('adminApi/admin/car_order_decision/order_list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
              this.tableData = data
        })
      }
    },

    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(this.searchForm),1000)
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    handleSee(index, row,bool){
      this.dialogSendData.isAdd=false;
      this.dialogSendData.id=row.id;
      this.dialogSendData.dialogFormVisible=true;
/*      退单流程的状态：退单已申请、退单物管通过、退单物管未通过、退单风控未通过、已退单
        非退单流程的状态：已保存、已提交、审核中、初审通过、二审不通过、二审通过、待付款、
        付款中、已付款、回款中、已结清
        退单是 true 非退单是false
        */
      if (row.status==-1||row.status==-2||row.status==180||row.status==190||row.status==210) {
       this.dialogSendData.isBack='退单';
      }else if(row.status==-4){
        this.dialogSendData.isBack='取消';
      }else{
       this.dialogSendData.isBack='打款回款'
      }

    },
   
    getStatusMap(){
      agentHttp.get('adminApi/admin/car_order_decision/get_status_map' ).then((data)=>{
        this.statusMap = data.data.orderStatus;
        this.orderTypeMap = data.data.orderType;
        this.logisticsStatusMap = data.data.logisticsStatus;
        this.cashDepositStatusMap = data.data.cashDepositStatus;
        this.carInspectionStatusMap = data.data.carInspectionStatus;
        this.logisticsFollowStatusMap = data.data.logisticsFollowStatus;
      })  
    },
   
    //时间空间方法
  
    /*send(){
      eventIsAdd.$emit('eventIsAdd', this.isAdd);
    }*/
  }
}
